<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<title>凯盛项目管理系统</title>
	<link rel="stylesheet" href="css/bootstrap.css" type="text/css" />
	<link rel = "Shortcut Icon" href="http://www.kaishengit.com/favicon.ico" />
	<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
	<div class="container">
		<div class="navbar">
			<div class="navbar-inner">
				<div class="container">
					<a href="main" class="brand">凯盛项目管理系统</a>
					<ul class="nav pull-right">
						<li class="active">
							<a>${user.name }</a>
						</li>
						<li>
							<a href="user">个人资料</a>
						</li>
						<li class="divider-vertical"></li>
						<li>
							<a href="loginout">安全退出</a>
						</li>
					</ul>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="span3">
				<div class="wall">
					<ul class="nav nav-list">
						<li class="nav-header">个人资料</li>
						<li class="divider"></li>
						<li class="active">
							<a href="user">
								<i class="icon-white icon-user"></i>个人资料
							</a>
						</li>
						<li>
							<a href="user?m=password">
								<i class="icon-qrcode"></i>修改密码
							</a>
						</li>
					</ul>
				</div>
			</div>
			<div class="span9">
                <form action = "user" method = "post" class="form-horizontal">
                    <fieldset>           
                        <legend>修改个人资料</legend>
                        <c:choose>
							<c:when test="${param.code == '10001' }">
								<div class="well" id="naperror">密码错误或服务器忙，修改失败！</div>
							</c:when>
							<c:when test="${param.code == '10002' }">
								<div class="well" id="ftl">修改成功！</div>
							</c:when>
						</c:choose>
						<div class="control-group">
                            <label class="control-label">账户状态</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" name="state" disabled="disabled" value = "${user.enable }">
                            </div>
                        </div>
						<div class="control-group">
                            <label class="control-label">上次登录IP</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" name="ip" disabled="disabled" value ="${user.ip }">
                            </div>
                        </div>
						<div class="control-group">
                            <label class="control-label" >上次登录时间</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge"  name="time" disabled="disabled" value = "${user.timeString }">
                            </div>
                        </div>
						<div class="control-group" id ="nameDiv">
                            <label class="control-label" for="name" >修改登录名</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" id="name" name="name" value ="${user.name }">
                           		 <p class="help-block" id="pname" ></p>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="company">输入确认密码</label>
                            <div class="controls">
                                <input type="password" class="input-xlarge" id="company" name="password">
                            </div>
                        </div>
                        <div class="form-actions">
                            <button class="btn btn-primary" type="submit" disabled = "disabled" id ="btn">修改</button>
                            <a href="main" class="btn">返回</a>
                        </div>
                    </fieldset>
                </form>
            </div>
        </div>
    </div>
    <script type="text/javascript">
    	$(document).ready(function() {
    		var oldName = $("#name").val();
    		$("#name").focus(function() {
    			$("#nameDiv").removeClass("error");
    			$("#pname").html("");
    		});
    		
	    	$("#name").blur(function() {
	    		var name = $(this).val();
	    		if(name.trim() == "") {
	    			$("#nameDiv").addClass("error");
	    			$("#pname").html("用户名不能为空");
	    		} else if(name != oldName) {
	    			$.get("user?m=name&name=" + name,function(result){
	    				if(result == 0){
		                		$("#pname").text("用户名可用");
		                		$("#btn").removeAttr("disabled");
		                	} else {
		                		$("#pname").text("用户名已被占用！");
		                    	$("#nameDiv").addClass("error");
		                    	$("#btn").attr("disabled","disabled");
		                	} 
	    			});
	    			
	    		} 
	    		
	    	});
    	});
    </script>
</body>
</html>